package com.csyaonie.android.jump;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.csyaonie.android.R;
import com.csyaonie.android.utils.ToastUtil;

public class AActivity extends AppCompatActivity {

    private Button jump_bt1;
    private Button jump_bt2;
    private Button call_action;
    private Button web_action;

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d("activityA","onNewIntent start");
        Log.d("activityA","taskId:"+getTaskId());
        Log.d("activityA","hashCode:"+hashCode());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_a);
        jump_bt1=findViewById(R.id.jump_bt1);
        jump_bt2=findViewById(R.id.jump_bt2);
        call_action=findViewById(R.id.call_action);
        web_action=findViewById(R.id.web_action);
        Log.d("activityA","taskId:"+getTaskId());
        Log.d("activityA","hashCode:"+hashCode());
        try {
            ActivityInfo activityInfo=getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            Log.d("activityA","任务名称:"+activityInfo.targetActivity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        jump_bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(AActivity.this,AActivity.class);
                startActivity(intent);
            }
        });

        jump_bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.显式
//                Intent intent=new Intent(AActivity.this,BActivity.class);
//                startActivity(intent);
                //2.显式
//                Intent intent=new Intent();
//                intent.setClass(AActivity.this,BActivity.class);
//                startActivity(intent);
                //3.显式
//                Intent intent=new Intent();
//                intent.setClassName(AActivity.this,"com.csyaonie.android.jump.BActivity");
//                startActivity(intent);
                //4.显式
//                Intent intent=new Intent();
//                intent.setComponent(new ComponentName(AActivity.this,"com.csyaonie.android.jump.BActivity"));
//                startActivity(intent);
                //5.隐式
                Intent intent=new Intent();
                intent.setAction("toBActivity");
//                intent.putExtra("name","zhangsan");
//                intent.putExtra("age",30);
                Bundle bundle=new Bundle();
                bundle.putString("name","lisi");
                bundle.putInt("age",33);
                intent.putExtras(bundle);
                startActivityForResult(intent,0);

            }
        });

        web_action.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("http://meituhai.com"));
                startActivity(intent);
            }
        });

        call_action.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:10086"));
                startActivity(intent);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        ToastUtil.show(AActivity.this,data.getExtras().getString("result"));
    }
}